<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
信息来源 <select name="sourceId">
        <c:forEach items="${sourceList}" var="s">
            <option value="${s.id}">${s.name}</option>
        </c:forEach>
</select><br>
状态 <input name="status"><br>


<button onclick="bing()">点击展示饼图</button>
<button onclick="excel()">点击excel</button>

<%--  存放图表的容器--%>
<div id="main"  style="height: 500px;width: 500px"> </div>

</body>


<script>

function excel(){

    let sourceId = $('[name=sourceId]').val();
    let status = $('[name=status]').val();
    location.href = '/excel.do?sourceId=' + sourceId +'&status=' + status
}


    function bing() {

            let sourceId = $('[name=sourceId]').val();
            let status = $('[name=status]').val();


            $.ajax({
                url:'/bing.do?sourceId=' + sourceId +'&status=' + status,

                success:function (data) {
                    console.log(data)

                    var chartDom = document.getElementById('main');
                    var myChart = echarts.init(chartDom);
                    var option;

                    option = {
                        title: {
                            text: 'Referer of a Website',
                            subtext: 'Fake Data',
                            left: 'center'
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                name: 'Access From',
                                type: 'pie',
                                radius: '50%',
                                data: data,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };

                    option && myChart.setOption(option);

                }



            })

    }

</script>


</html>